<template>
  <div style="position:relative">
    <FilterTable
      ref="table"
      :columns="columns"
      :params="fetchParams"
      :dataSource="list"
      :isColumnFilter="false"
      :isToperInfo="false"
      :isSelectColumn="false"
      :onColumnsChange="columns => (this.columns = columns)"
    >
    </FilterTable>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { getFwhdPjxmList, getFwhdCkdmList, getFwhdSfList } from '@/api/repair/business/customer/activity.js';
export default {
  name: 'Pjxm',
  mixins: [dictionary],
  props: ['ACTIVITY_CODE'],
  data() {
    // this.BaseTable = null;
    return {
      columns: this.createTable(),
      fetchApi: '',
      fetchParams: { xhrAbort: false },
      list: []
    };
  },
  created() {
    this.getFwhdPjxmList(this.ACTIVITY_CODE);
    this.getFwhdCkdmList();
    this.getFwhdSfList();
    console.log('传来的CODE', this.ACTIVITY_CODE);
  },
  // mounted() {
  //   this.BaseTable = this.$refs.basetable.$refs.pageTable;
  //   console.log(this.$router, this.$route, this.vin);
  // },
  methods: {
    createTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: '',
          sorter: true,
          render: props => {
            return <span>{}</span>;
          }
        },
        {
          title: '仓库代码',
          dataIndex: 'STORAGE_CODE',
          sorter: true,
          filterItems: [],
          render: props => {
            return <span>{this.func(props.row.STORAGE_CODE, 2)}</span>;
          }
        },
        {
          title: '备件代码',
          dataIndex: 'PART_NO',
          sorter: true
        },
        {
          title: '备件名称',
          dataIndex: 'PART_NAME',
          sorter: true
        },
        {
          title: '收费区分',
          dataIndex: 'CHARGE_PARTITION_CODE',
          sorter: true,
          filterItems: [],
          render: props => {
            return <span>{this.func(props.row.CHARGE_PARTITION_CODE, 5)}</span>;
          }
        },
        {
          title: '主要备件',
          dataIndex: 'IS_MAIN_PART',
          sorter: true,
          filterItems: [],
          render: props => {
            return <span>{this.createDictText(props.row.IS_MAIN_PART, '1278')}</span>;
          }
        },
        {
          title: '维修项目代码',
          dataIndex: 'LABOUR_CODE',
          sorter: true
        },
        {
          title: '计量单位名称',
          dataIndex: 'UNIT_CODE',
          sorter: true
        },
        {
          title: '备件数量',
          dataIndex: 'PART_QUANTITY',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '备件销售单价',
          dataIndex: 'PART_SALES_PRICE',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '备件销售金额',
          dataIndex: 'PART_SALES_AMOUNT',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '折扣率',
          dataIndex: 'DISCOUNT',
          sorter: true
        },
        {
          title: '折扣后金额合计',
          dataIndex: 'PART_SALES_AMOUNT_DISCOUNT',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '最新进货价',
          dataIndex: 'LATEST_PRICE',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '索赔价',
          dataIndex: 'CLAIM_PRICE',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '销售单价',
          dataIndex: 'SALES_PRICE',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '备件成本单价',
          dataIndex: 'COST_PRICE',
          sorter: true,
          summationPrecision: 2,
          summation: true
        },
        {
          title: '备件成本金额',
          dataIndex: 'COST_AMOUNT',
          sorter: true,
          summationPrecision: 2,
          summation: true
        }
      ];
    },
    async getFwhdPjxmList(row) {
      const res = await getFwhdPjxmList(row, {
        creditTimes: 1.0,
        afterlabour: 0,
        zkAmountLabour: 0,
        afterDiscountAmountPart: 0,
        zkAmountPart: 0,
        fag: 'U',
        labourList: '',
        partList: '',
        subjoinList: '',
        modelList: '',
        vehicleList: '',
        order: 'asc',
        limit: 10,
        offset: 0,
        dmsFuncId: 35100010,
        _: 1565681747515
      });
      this.list = res.rows;
      console.log('备件项目table', res);
    },
    async getFwhdCkdmList() {
      const res = await getFwhdCkdmList();
      this.columns[2].filterItems = res.map(x => ({ value: x.STORAGE_CODE, text: x.STORAGE_NAME }));
      console.log('仓库代码', this.columns[2].filterItems);
    },
    async getFwhdSfList() {
      const res = await getFwhdSfList();
      this.columns[6].filterItems = res.map(x => ({ value: x.CHARGE_PARTITION_CODE, text: x.CHARGE_PARTITION_NAME }));
      console.log('收费区分', this.columns[6].filterItems);
    },
    func(val, num) {
      if (val) {
        const res = this.columns[num].filterItems.find(x => x.value == val);
        return res.text;
      }
    }
  }
};
</script>
